<template>
	<view hover-class="bg-light" class="pt-1" :class="item.istop?'bg-light':'bg-white'">
		<div class="flex align-stretch " @click="onClick" @longpress="long">
			<view class="flex align-center justify-center position-relative" style="width: 145rpx;">
				<free-avatar :src="item.avatar" size="92"></free-avatar>
				<free-badge :num="item.noreadnum" v-if="item.noreadnum" badgeClass="position-absolute" badgeStyle="right: 12rpx;top: 2rpx;"></free-badge>
			</view>
			<view class="flex-1 py-2 pr-2 border-bottom" style="width: 557rpx;">
				<view class="flex align-center justify-between">
					<text class="font" style="width: 400rpx;">{{itemName}}</text>
					<text class="font-sm text-light-muted flex-shrink">{{item.update_time| getTime}}</text>
				</view>
				<text class="font-sm text-light-muted pt-1 text-ellipsis" >{{item.data}}</text>
			</view>
		</div>
	</view>
</template>

<script>
	import freeAvatar from "@/components/free-ui/free-avatar.vue"
	import freeBadge from "@/components/free-ui/free-badge.vue"
	import freeBase from "@/common/mixin/free-base.js"
	import { mapState } from "vuex"
	
	export default {
		
		mixins:[freeBase],
		props:{
			item:{
				type:Object
				
			},
			index:{
				type:Number,
				default:0
			}
		},
		computed:{
			...mapState({
				chat:state=>state.user.chat,
			}),
			itemName(){
				  
				 if(this.item.name){
					 return this.item.name.length>14?this.item.name.slice(0,14)+'...':this.item.name
				 }
			}
		},
		components:{
			freeAvatar,freeBadge
		},
		methods:{
			onClick(){
				 this.chat.readChatItem(this.item.id,this.item.chat_type)
				 
				 uni.navigateTo({
				 	url: '/pages/chat/chat?params='+encodeURIComponent(JSON.stringify(this.item)),
				 	
				 });
				 //清除角标
			},
			long(e){
				let x = 0
				let y = 0
				//手机端
				// #ifdef APP-PLUS-NVUE
				if(Array.isArray(e.changedTouches) && e.changedTouches.length>0){
					x = e.changedTouches[0].screenX
					y = e.changedTouches[0].screenY
				}
				// #endif
				// #ifdef H5
				x = e.changedTouches[0].pageX
				y = e.changedTouches[0].pageY
				// #endif
				//小程序
				// #ifdef MP
				x=e.detail.x
				y=e.detail.y
				// #endif
				this.$emit('long',{
					x,
					y,
					index:this.index,
					
					})
			
			}
		}
	}
</script>

<style>
</style>
